// BFAvisionDlg.h : header file
//
//{{AFX_INCLUDES()
#include "NiKnob.h"
#include "NiButton.h"
#include "NiSlide.h"
//}}AFX_INCLUDES

#if !defined(AFX_BFAVISIONDLG_H__D24313B9_DC8A_4A04_A3E4_B7B58B890427__INCLUDED_)
#define AFX_BFAVISIONDLG_H__D24313B9_DC8A_4A04_A3E4_B7B58B890427__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "mil.h"

#include "rectangletrack.h"

//#include "circletrack.h"

long MFTYPE DisplayErrorExt(long HookType, MIL_ID EventId, void MPTYPE *UserDataPtr) ;

/////////////////////////////////////////////////////////////////////////////
// CBFAvisionDlg dialog
#define BUF_NUM 10

#define RTRACK_NUM 20
#define CTRACK_NUM 20

#define CAMSIZE_X 2048

class CBFAvisionDlg : public CDialog
{
// Construction
public:
	CBFAvisionDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CBFAvisionDlg)
	enum { IDD = IDD_BFAVISION_DIALOG };
	CStatic	m_staticImage;
	BOOL	m_bThreshold;
	CNiSlide	m_slideThreshold;
	BOOL	m_bApplyFlatFilter;
	CNiButton	m_btnSettings;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBFAvisionDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CBFAvisionDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnMove(int x, int y);
	afx_msg void OnDestroy();
	afx_msg void OnButtonGrab();
	afx_msg void OnButtonStop();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnClickCwbooleanThreshold();
	afx_msg void OnPointerValueChangedCwslideThreshold(long Pointer, VARIANT FAR* Value);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnButton1();
	afx_msg void OnButton2();
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnButtonLive();
	afx_msg void OnButtonEnable();
	afx_msg void OnButtonDisable();
	afx_msg void OnButtonMakeFlatFilter();
	afx_msg void OnCheckApply();
	afx_msg void OnClickCwbooleanPower();
	afx_msg void OnClickCwbooleanView();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	DECLARE_EVENTSINK_MAP()
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public :
	BOOL m_isCurrentlyHookedOnErrors ;

	MIL_ID m_MilImage[BUF_NUM] ;	// Image buffer identifier.

	MIL_ID m_MilOverlayImage ;

	BYTE m_dThreshold ;

	long MFTYPE DisplayError(long HookType, MIL_ID EventId, void MPTYPE *UserDataPtr) ;

	void HookedOnErrors(bool IsHooked){m_isCurrentlyHookedOnErrors = IsHooked ;} ;
	void Binarize(MIL_ID srcBuf, MIL_ID destBuf, BYTE value) ;
	void Rotate(MIL_ID srcBuf, MIL_ID destBuf) ;

private :
	MIL_INT64 m_bufferAttributes ; // Buffer attributes that will be allocated

	MIL_ID m_MilDisplay ; // Display identifier

	long m_imageSizeX ;		  // Buffer Size X
	long m_imageSizeY ;		  // Buffer Size Y
	long m_imageSize ;

	long m_digitizerSizeX ;	  // Digitizer input width
	long m_digitizerSizeY ;	  // Digitizer input height
	long m_digitizerNbBands ; // Number of input color bands of the digitizer

	long m_bitSize ;

	BOOL m_isGrabStarted ;	  // State of the grab

	long m_numberOfDigitizer ; // Number of digitizers available on the system

	double m_zoom, m_xOffset, m_yOffset, m_preZoom ;
	double m_xMargin, m_yMargin ;

	BYTE* m_pUserBuf[10] ;
	
	MIL_ID m_MilApplication ; // Application identifier.  
	MIL_ID m_MilSystem ;      // System identifier.       
	MIL_ID m_MilDigitizer ;	  // Digitizer identifier.

	MIL_ID m_test ;
	
	void InitMatrox() ;
	void ExitMatrox() ;

	CPoint m_RPoint[2] ;

	CRectangleTrack m_rTrack[RTRACK_NUM] ;

	//CCircleTrack m_cTrack[RTRACK_NUM][20][10] ;
	CRect m_cTrack[RTRACK_NUM][CTRACK_NUM][CTRACK_NUM] ;

	int m_rTrackNum ;
	int m_curTrack ;

	HDC m_hCustomDC ;

	BOOL m_bRDown, m_bLDown ;

	void BeforeOverlay() ;

	void AfterOverlay() ;

	int m_WIDTH ;
	int m_HEIGHT ;

	int m_nCursor ;

	CRect m_midRect ;

	double m_flatData[CAMSIZE_X] ;

	void DrawRectangle() ;
	void MakeFlatFilter(MIL_ID srcBuf, double factor) ;
	void ReadFlatFilter() ;
	
public :
	CPoint m_prePoint[2] ;

	CString m_iniFile ;

	int m_curBuf ;

	BOOL m_timerFlag[256] ;

	CBrush m_brush ;

	void ApplyFlatFilter(MIL_ID srcBuf, MIL_ID destBuf) ;
} ;

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BFAVISIONDLG_H__D24313B9_DC8A_4A04_A3E4_B7B58B890427__INCLUDED_)
